#!/usr/bin/perl
use Spreadsheet::ParseXLSX;
use Excel::Writer::XLSX;
use utf8;
use Data::Dumper;
binmode(STDIN,':encoding(utf8)');
binmode(STDOUT,':encoding(utf8)');

sub gen_xlsx {
  $timetbl = @_[0];
  $o_file = @_[1];
  $version = @_[2];

my $workbook_o = Excel::Writer::XLSX->new("$o_file");
my $worksheet_o = $workbook_o->add_worksheet('课程表');
my $format = $workbook_o->add_format();
$format->set_bold();
$format->set_color('black');
$format->set_align('center');
$worksheet_o->write(2 ,2 ,'课程表' ,$format);
$worksheet_o->write(2 ,3 ,'星期一' ,$format);
$worksheet_o->write(2 ,4 ,'星期二' ,$format);
$worksheet_o->write(2 ,5 ,'星期三' ,$format);
$worksheet_o->write(2 ,6 ,'星期四' ,$format);
$worksheet_o->write(2 ,7 ,'星期五' ,$format);
$worksheet_o->write(3 ,2 ,'8:00-9:30' ,$format);
$worksheet_o->write(4 ,2 ,'10:00-11:30' ,$format);
$worksheet_o->write(5 ,2 ,'13:30-15:00' ,$format);
$worksheet_o->write(6 ,2 ,'15:30-17:00' ,$format);
$worksheet_o->write(7 ,2 ,'19:00-20:30' ,$format);
my $timetbl_one = @$timetbl[$version];
print Dumper($timetbl_one);
my @timetbl_key = keys %$timetbl_one;
my @timetbl_key_s = sort { $a <=> $b } @timetbl_key;
my $col;
my $row;
foreach my $col_row (@timetbl_key_s) {
  print Dumper($timetbl_one->{"$col_row"});
  ($col => $row) = &parse_num($col_row ,$col ,$row);
  print "col:$col;row:$row\n";
  $worksheet_o->write($row+2 ,$col+2 ,$timetbl_one->{"$col_row"} , $format)
}
$workbook_o->close();
}

sub parse_num {
  my $col_row = @_[0];
  my $col = @_[1];
  my $row = @_[2];

  $row = $col_row % 10;
  $col = ($col_row-$row) / 10;
  ($col => $row);
}
